package com.citywithincity.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.citywithincity.db.interfaces.IDbDescriptorFactory;
import com.citywithincity.db.interfaces.SqlDriver;
import com.citywithincity.db.meta.DbStructFactory;

/**
 * 数据库连接描述
 * @author Randy
 *
 */
public abstract class ConnectionDescription implements IDbDescriptorFactory{
	
	//数据库连接相关属性
	private String driverClass;
	private String user;
	private String password;
	private String server;
	private int port;
	
	
	public ConnectionDescription() {
		
	}
	
	/*
	public ConnectionDescription(String driverClass,String jdbcUrl,String user,String password){
		this.driverClass = driverClass;
		this.jdbcUrl = jdbcUrl;
		this.user = user;
		this.password = password;
	}*/
	

	
	private SqlDriver driver;

	public final SqlDriver getSqlDriver() {
		if(driver==null) {
			synchronized (this) {
				if(driver == null) {
					driver= createDriver();
				}
			}
		}
		
		return driver;
	}


	protected abstract SqlDriver createDriver() ;

	private DbStructFactory struct;
	
	public final DbStructFactory getStruct() {
		if(struct==null) {
			synchronized (this) {
				if(struct == null) {
					struct= createStruct(getSqlDriver());
				}
			}
		}
		
		return struct;
	}


	protected abstract DbStructFactory createStruct(SqlDriver sqlDriver);

	public String getUser() {
		return user;
	}


	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	public String getDriverClass() {
		return driverClass;
	}


	public void setDriverClass(String driverClass) {
		this.driverClass = driverClass;
	}


	public abstract String getJdbcUrl() ;

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void setUser(String user) {
		this.user = user;
	}





	
}
